pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let start_index = num_str.find('(').expect("Invalid input format");
    let end_index = num_str.find(')').expect("Invalid input format");

    let value_str = &num_str[..start_index];
    let from_base: u32 = num_str[start_index + 1..end_index]
        .parse()
        .expect("Invalid base format");

    let decimal_value = u32::from_str_radix(value_str, from_base)
        .expect("Invalid number for the given base");

    let result = to_base_string(decimal_value, to_base);

    result
}

fn to_base_string(mut num: u32, base: u32) -> String {
    if num == 0 {
        return "0".to_string();
    }

    let mut result = String::new();
    while num > 0 {
        let remainder = num % base;
        let digit = if remainder < 10 {
            (b'0' + remainder as u8) as char
        } else {
            (b'a' + (remainder - 10) as u8) as char
        };
        result.push(digit);
        num /= base;
    }
    result.chars().rev().collect()
}